home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / HEX16IN < prev    next >
Encoding:
Text File  |  1985-12-22  |  1.6 KB  |  56 lines

  1. ;-------------------------hex16in routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 51
  4. ;
  5. ; NAME HEX16IN
  6. ; ROUTINE FOR Conversion from ASCII Hexidecimal to 16-bit binary
  7. ;
  8. ; FUNCTION: This routine accepts a hexidecimal number from the std input
  9. ; device and converts it to internal 16-bit binary form.
  10. ;
  11. ; INPUT: The individual digits of the hexxidecimal number are received in
  12. ; ASCII through a call to a std I/O routine.  The valid digits are 0 - 9
  13. ; and A - F.  An ASCII code for other than a valid digit will terminate
  14. ; the routine.
  15. ; OUTPUT: A 16-bit binary number is returned in DX.
  16. ; REGISTERS USED:  Only DX is modified.  It returns the result.
  17. ; SEGMENTS REFERENCED:  None
  18. ; ROUTINES CALLED:  STDIN
  19. ; SPECIAL NOTES: None
  20. ;
  21. ; ROUTINE TO CONVERT FROM ASCII HEXIDECIMAL TO INTERNAL 16-BIT BINARY.
  22. ;
  23. hex16in    proc    far
  24. ;
  25.     push    cx        ; save registers
  26.     push    ax
  27. ;
  28.     mov    dx,0        ; initialize DX
  29. ;
  30. hex16in1:
  31.     call    stdin        ; a digit comes in in AL
  32.     sub    al,30h        ; reduce from ASCII
  33.     jl    hex16in3    ; check if too low
  34.     cmp    al,9
  35.     jle    hex16in2    ; go of OK
  36.     and    al,5Fh        ; for lower case too
  37.     sub    al,7        ; adjust for A - F
  38.     jl    hex16in3    ; too low for A - F
  39.     cmp    al,15        ; check if too high
  40.     jg    hex16in3
  41. ;
  42. hex16in2:
  43.     cbw            ; convert to word
  44.     mov    cl,4        ; for a count of four
  45.     sal    dx,cl        ; shift DX left
  46.     add    dx,ax        ; add in digit
  47.     jmp    hex16in1
  48. ;
  49. hex16in3:
  50.     pop    ax        ; restore registers
  51.     pop    cx
  52.     ret            ; return
  53. ;
  54. hex16in    endp
  55. ;-------------------------hex16in routine ends---------------------------+
  56.